$totalBet = Read-Host "Pls enter how many round of game you want to play "
$playA = Read-Host "Pls enter name of player A "
$playB = Read-Host "Pls enter name of player B "
$i = 1
$cards = @("rock", "scissor", "cloth")
$logFile ="C:\hr\2025-09-09-GameLog.txt"


function getCard() {
    return Get-Random -Minimum 1 -Maximum 4
}
    
function bet($result) {
    switch ($result) {
        -2 { return "you lose ~" }
        1 { return "you lose ~" }
        -1 { return "you win ~" }
        2 { return "you win ~" }
        # 0 { return "draw" }
    }
}

while ($true) {
    
    <#
    #if there is draw, execute the folliwing code block as plan B
    $roleA = getCard
    $roleB = getCard
    #>

    # if there is no draw, execute the folliwing code block as plan A
    do {
        $roleA = getCard
        $roleB = getCard
    }while ($roleA -eq $roleB)

    $result = $roleA - $roleB
    # $betResult=bet($result) # this is the first way to call function
    $betResult = bet $result # this is the second way to call function
    # $betResult

    # $finalResult = Write-Host "$playA : $($cards[$roleA-1]) VS $playB : $($cards[$roleB-1]) => $betResult"
    
    # variables with write-host cannot be used in out-file
    
    $finalResult = "$playA : $($cards[$roleA-1]) VS $playB : $($cards[$roleB-1]) => $betResult"
   
    # $finalResult | Out-File -FilePath $logFile -Encoding utf8 -Append


    if ($i -eq $totalBet) {
        break
    }
    $i++

    # test bymyself, out-file can be used here before the loop break
    $finalResult | Out-File -FilePath $logFile -Encoding utf8 -Append

}


